package com.yxx.controller.admin;

import com.yxx.medicinecommon.result.PageResult;
import com.yxx.medicinecommon.result.ResponseResult;
import com.yxx.medicinepojo.dto.OrdersCancelDTO;
import com.yxx.medicinepojo.dto.OrdersConfirmDTO;
import com.yxx.medicinepojo.dto.OrdersPageQueryDTO;
import com.yxx.medicinepojo.dto.OrdersRejectionDTO;
import com.yxx.medicinepojo.vo.OrderReportStatisticVO;
import com.yxx.medicinepojo.vo.OrderStatisticsVO;
import com.yxx.medicinepojo.vo.OrderVO;
import com.yxx.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yuxiangxun
 * @date 2024/9/16
 * @apiNote
 */
@Slf4j
@Api(tags = "订单管理相关接口")
@RequestMapping("/admin/order")
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 订单搜索（分页查询）
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索（分页查询）")
    public ResponseResult<PageResult> pageQueryOrder(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
        return ResponseResult.success(pageResult);
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation("订单详情查询")
    public ResponseResult<OrderVO> orderDetails(@PathVariable("id") Long id){
        OrderVO orderVO = orderService.orderDetails(id);
        return ResponseResult.success(orderVO);
    }

    /**
     * 订单各个状态的数量统计
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("订单各个状态的数量统计")
    public ResponseResult orderStatistics(){
        OrderStatisticsVO orderStatisticsVO = orderService.orderStatics();
        return ResponseResult.success(orderStatisticsVO);
    }

    /**
     * 订单接单功能（点击接单修改订单状态）
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public ResponseResult OrderConfirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.OrderConfirm(ordersConfirmDTO);
        return ResponseResult.success();
    }

    /**
     * 订单拒单功能（点击拒单修改订单状态）同时实现支付功能（现在先不做）
     * @param ordersRejectionDTO
     * @return
     */
    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public ResponseResult OrderRejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception{
        orderService.OrderRejection(ordersRejectionDTO);
        return ResponseResult.success();
    }

    /**
     * 订单取消功能（点击取消修改订单状态） 同时实现支付功能（现在先不做）
     * @param ordersCancelDTO
     * @return
     * @throws Exception
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public ResponseResult OrderCancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception{
        orderService.OrderCancel(ordersCancelDTO);
        return ResponseResult.success();
    }

    /**
     * 订单派送功能
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("订单派送")
    public ResponseResult OrderDelivery(@PathVariable("id") Long id) throws Exception{
        orderService.OrderDelivery(id);
        return ResponseResult.success();
    }

    /**
     * 完成订单功能
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public ResponseResult OrderComplete(@PathVariable("id") Long id) throws Exception {
        orderService.OrderComplete(id);
        return ResponseResult.success();
    }

}
